//Monday, November 16 2009
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

#define 	maxn	100

class ThreePhotos
{
public:
	int removeCubes(vector <string> A, vector <string> B, vector <string> C)
	{
		int N = A.size();
		int ret = N*N*N;
		//vector<vector<vector<bool> > > v(N, vector<vector<bool> > (N, vector<bool> (N, false)));
		for(int i=0; i<N; i++)
			for(int j=0; j<N; j++)
				for(int k=0; k<N; k++)
				{
					if ( (A[i][j]=='Y')&&(B[i][k]=='Y')&&(C[j][k]=='Y') )
					{
						ret--;
						a[i][j] = true;
						b[i][k] = true;
						c[j][k] = true;
					}
				}
		for(int i=0; i<N; i++)
			for(int j=0; j<N; j++)
			{
				if ( (A[i][j]=='Y') && (!a[i][j]) ) return -1;
				if ( (B[i][j]=='Y') && (!b[i][j]) ) return -1;
				if ( (C[i][j]=='Y') && (!c[i][j]) ) return -1;
			}
		return ret;
	}
	bool a[maxn][maxn],b[maxn][maxn],c[maxn][maxn];
};
